package com.lagou.homework.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SortMapper extends Mapper<LongWritable,Text,IntWritable,NullWritable> {
    //重写Mapper类的map方法
    //把读取到的数据作为key即可，hadoop会根据key的compare方法自行排序
    IntWritable nkey=new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //.接受到文本内容，转为String类型
        String s = value.toString().trim();
        //fuzhi
        nkey.set(Integer.valueOf(s));
        context.write(nkey,NullWritable.get());
    }
}
